package agentsSME;

import java.util.LinkedList;

import otherOrganizations.ServiceRecord;

public class Employee {
	private int employeeCode;
	private boolean busy;
	//private boolean atWork;
	private LinkedList<BehaviourHistory> behaviourHistory;
//	private LinkedList<BehaviourHistory> serviceHistory;
	
	public Employee(int code) {
		employeeCode = code;
		setBusy(false);
//		atWork= true;
		behaviourHistory = new LinkedList<BehaviourHistory>();
//		serviceHistory = new LinkedList<BehaviourHistory>();
	}

	public int getEmployeeCode() {
		return employeeCode;
	}

	public void setEmployeeCode(int employeeCode) {
		this.employeeCode = employeeCode;
	}
	/*
	public void setAtWork (boolean b){
		atWork=b;
	}
	public boolean getAtWork(){
		return atWork;
	}
	*/
	public boolean isBusy() {
		return busy;
	}

	public void setBusy(boolean busy) {
		this.busy = busy;
	}

	public LinkedList<BehaviourHistory> getBehaviourHistory() {
		return behaviourHistory;
	}
	/*
	public LinkedList<BehaviourHistory> getServiceHistory() {
		return serviceHistory;
	}
	*/
	public LinkedList<String> executedTwice(String s){
		LinkedList<String> list = new LinkedList<String>();
		int count =0;
		for (int i=0; i<behaviourHistory.size(); i++){			
			if (s.equals(behaviourHistory.get(i).getName())){
				count++;
			}			
		}
		if(count>1){
			list.add(s);
		}
		return list;
	}
	public boolean hasBehaviour(String s){
		boolean x = false;
		int count =0;
		for (int i=0; i<behaviourHistory.size(); i++){			
			if (s.equals(behaviourHistory.get(i).getName())){
				count++;
			}			
		}
		if(count>0){
			x=true;
		}
		return x;
	}
	public LinkedList<BehaviourHistory> getBHbyName(String s){
		LinkedList<BehaviourHistory> history = new LinkedList<BehaviourHistory>();
		for (int i=0; i<behaviourHistory.size(); i++){			
			if (s.equals(behaviourHistory.get(i).getName())){
				history.add(behaviourHistory.get(i));
			}			
		}
		return history;
	}

	public String toString(){
		String s1= "Employee "+ employeeCode + " : is busy ( " + busy+  " ) and has done: ";
		String s = " ";
		if(behaviourHistory.size()==0){
			s = "Nothing";
		}
		if(behaviourHistory.size()>0){
			for (int i=0; i< behaviourHistory.size(); i++){
				s= s+ behaviourHistory.get(i).getName() + "; ("+behaviourHistory.get(i).getStart()+"   "+behaviourHistory.get(i).getEnd();
			}
		}
		return s1+s ;
	}

	

}
